﻿
Namespace std
    Public Module helper
        'read a0, a1, a2, ... from map(of string, valueT) to [set](of valueT)
        Public Function readlist(Of valueT As IComparable(Of valueT)) _
                                (ByVal data As map(Of String, valueT), ByVal countname As String _
                                 , ByVal keyname As String, ByRef result As [set](Of valueT) _
                                 , Optional ByVal ignoreEmptyEntity As Boolean = False) As Boolean
            If result Is Nothing Then
                result = New [set](Of valueT)
            Else
                result.clear()
            End If

            Dim vec As vector(Of valueT) = Nothing
            If readlist(data, countname, keyname, vec, ignoreEmptyEntity) Then
                Dim i As Int64
                For i = 0 To vec.size() - 1
                    result.insert(vec(i))
                Next

                Return True
            Else
                Return False
            End If
        End Function

        Public Function readlist(Of valueT)(ByVal data As map(Of String, valueT), ByVal countname As String _
                                            , ByVal keyname As String, ByRef result As vector(Of valueT) _
                                            , Optional ByVal ignoreEmptyEntity As Boolean = False) As Boolean
            If result Is Nothing Then
                result = New vector(Of valueT)()
            Else
                result.clear()
            End If

            Dim count As Int64
            count = convertor.cast(Of Int64)(data(countname))
            If count <= 0 Then
                raiseError("do not get valid " + Convert.ToString(countname) + " parameter from data." _
                           , errorHandle.errorType.warning)
                Return False
            End If

            Dim i As Int64
            For i = 0 To count - 1
                Dim s As valueT = Nothing
                s = data(keyname + Convert.ToString(i))
                If Not ignoreEmptyEntity OrElse Not s Is Nothing Then
                    result.push_back(s)
                End If
            Next

            Return True
        End Function
    End Module
End Namespace
